package com.yakami.ocean.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jakewharton.rxbinding.view.RxView;
import com.yakami.ocean.R;
import com.yakami.ocean.adapter.base.BaseListAdapter;
import com.yakami.ocean.bean.TestPaperProfile;

import java.util.concurrent.TimeUnit;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author Yakami, Created on 2016/4/21
 */
public class DialogPaperAdapter extends BaseListAdapter<TestPaperProfile> {

    public DialogPaperAdapter(Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TestViewHolder(mInflater.inflate(R.layout.item_dialog, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        TestViewHolder newsHolder = (TestViewHolder) holder;
        TestPaperProfile tmp = getItem(position);
        newsHolder.text.setText(tmp.name);
    }


    class TestViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.dialog_list_item) TextView text;

        public TestViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
            RxView.clicks(view)
                    .throttleFirst(500, TimeUnit.MILLISECONDS)
                    .subscribe((Void) -> {
                                if (mItemClickListener != null) {
                                    int pos = getAdapterPosition();
                                    mItemClickListener.onClick(pos, getItem(pos));
                                }
                            }
                    );
        }
    }
}
